package cn.pugle.base.thread;

import cn.pugle.base.net.socket.client.CONS;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.Scanner;

/**
 * @author tzp
 * @since 2020/10/26
 */
public class ThreadStateTest {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    ServerSocket serverSocket = new ServerSocket(CONS.SERVER_PORT, 100, CONS.inetAddress);
                    serverSocket.accept();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }, "t1");
        System.out.println(t1.getState());//new
        t1.start();
        System.out.println(t1.getState());//runnable
        t1.interrupt();
        System.out.println(t1.getState());//runnable
//        t1.stop();

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Scanner scanner = new Scanner(System.in);
                    scanner.nextLine();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "t1");
        System.out.println(t2.getState());//new
        t2.start();
        System.out.println(t2.getState());//runnable
        t2.interrupt();
        System.out.println(t2.getState());//runnable
//        t2.stop();

    }
}
